<?php

/*
 * litchicms
 * Copyright (C) 2010-7-7 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");


$Component_can_action = array('sort', 'top');

if (empty($RT['v']['fire']) || !in_array($RT['v']['fire'], $Component_can_action))
    $RT['v']['fire'] = 'sort';

switch ($RT['v']['fire']) {
    case 'sort':
        if (empty($_POST['Component_options']['id']) || !is_array($_POST['Component_options']['id'])) {
            return false;
        }
        foreach ($_POST['Component_options']['id'] as $k => $value) {
            $value = intval($value);
            $id = intval($k);
            if ($value != 0 && $id != 0) {
                brk_update($COLLECTION_TABLENAME, array('sort' => $value), "WHERE id=$id");
            }
        }
        return TRUE;
        break;

    case 'top':
        if (!_filter_id()) {
            return false;
        }
        foreach ($_POST['field']['coll_selected'] as $value) {
            $value = intval($value);
            if ($value != 0) {
                $temp = brk_select_one($COLLECTION_TABLENAME, 'top', "WHERE id=$value");
                brk_update($COLLECTION_TABLENAME, array('top'=>$temp['top']?0:1), "WHERE id=$value");
            }
        }
        return TRUE;
        break;

    default:
        break;
}